*All graphs, Grewal and Voeten "Are New Democracies Better Human Rights Compliers"
*Data is all in STATA13format

***Balance graph (figure 1)

use "C:\Users\ev42\Dropbox\ECHRCompliance\Replication\balancedata.dta", clear

graph dot (mean) UnMatched (mean) Matched (mean) MaxBalance, over(A, sort(id)) marker(1, msize(medlarge) msymbol(lgx)) marker(2, msize(medium) msymbol(circle)) marker(3, msize(medium) msymbol(square))  yline(0) ///
title("  ", size(medium)) legend(order(1 "Unmatched Sample"  2 "Matched Sample" 3 "Matched Sample, Max Balance")) scheme(s1color)

***Kaplan-Meier plots (figure 2)

*This is for the unmatched data

use "C:\Users\ev42\Dropbox\ECHRCompliance\Replication\GrewalVoetendata.dta", clear

sts graph, by(newdem2) ci xtitle(Days until Judgment Implemented) title(Unmatched Sample)  legend(off) xlabel(0(1000)6000) scheme(s2mono)  graphregion(fcolor(white))

sts graph, by(newdem3) ci xtitle(Days until Judgment Implemented) title(Unmatched Sample)  legend(off) xlabel(0(1000)6000) scheme(s2mono)  graphregion(fcolor(white))

*These two graphs are for the matched data

use "C:\Users\ev42\Dropbox\ECHRCompliance\Replication\matcheddata2.dta", clear
stset Duration [iw=weights], failure(Pending==0) 

sts graph, by(newdem2) ci xtitle(Days until Judgment Implemented) title(Matched Sample)  legend(off) xlabel(0(1000)6000) scheme(s2mono)  graphregion(fcolor(white))



use "C:\Users\ev42\Dropbox\ECHRCompliance\Replication\matcheddata3.dta", clear
stset Duration [iw=weights], failure(Pending==0) 

sts graph, by(newdem3) ci xtitle(Days until Judgment Implemented) title(Matched Sample)  legend(off) xlabel(0(1000)6000) scheme(s2mono)  graphregion(fcolor(white))

***Figure 3

*First panel
use "C:\Users\ev42\Dropbox\ECHRCompliance\Replication\matcheddata2.dta", clear
stset Duration [iw=weights], failure(Pending==0) 
stcox  newdem2 execap SepOp Importance grandchamber INDIVIDUAL JP_dummy LEG_dummy PRACT_dummy EXE_ADM_dummy  NArticles lnothers Article2or3_dummy Article5_dummy Article6_dummy Article8_dummy  Article10_dummy  Article13_dummy  P1_1dummy,  tvc( newdem2 execap INDIVIDUAL NArticles lnothers Article5_dummy Article6_dummy Article10_dummy ) texp(ln(_t)) 

**The following code builds on Amanda A. Licht, 2011, "Replication data for: Change Comes with Time", http://hdl.handle.net/1902.1/15633 IQSS Dataverse Network [Distributor] V3 [Version]

****************************/
*** Combined Coefficient ***/
****************************/
*Following estimation of the NPH model, generate combined coefficient and standard errors using parameters from the matrices stored in e(b) and e(V)*/

mat def b=e(b)
mat def V=e(V)

mat list b
mat list V

/*identify position of variance of beta for constitutive and interaction terms*/
/*generate combined coef*/

gen combcoef = b[1,1] + ln(_t)*b[1,20]

gen se_combcoef = sqrt(V[1,1] + (ln(_t))^2*V[20,20] + 2*ln(_t)*V[1,20])


gen combcoef_lo = combcoef - 1.96*se_combcoef
gen combcoef_hi = combcoef + 1.96*se_combcoef


/******************************************/
/*** Relative Hazard for Binary Variable***/
/******************************************/
/*Following procedure to calculate combined coefficient, exponentiate to create the relative hazard*/
/*calculate relative hazard*/
gen relhaz = exp(combcoef)
/*calculate 95% confidence intervals*/
gen relhaz_lo = exp(combcoef_lo)
gen relhaz_hi = exp(combcoef_hi)
/*chart effect with confidence bounds*/

  *With overlaid histogram
  twoway (line relhaz relhaz_lo relhaz_hi _t if _t>365, sort clpattern(solid dash dash) clwidth(thick medium medium) ) ///
  (histogram _t, yaxis(2) fcolor(none) lwidth(vthin) lcolor(grey) lpattern(dash))  ///
 , ytitle(Relative Hazard New Versus Stable Democracy) yline(1) xtitle(Time Since Judgment) ///
   xlabel(0 1000 2000 3000 4000 5000) legend(off) scheme(s1mono)
   
   
   *Second panel
use "C:\Users\ev42\Dropbox\ECHRCompliance\Replication\matcheddata3.dta", clear
stset Duration [iw=weights], failure(Pending==0) 

set more off

stcox  newdem3 execap SepOp Importance grandchamber INDIVIDUAL JP_dummy LEG_dummy PRACT_dummy EXE_ADM_dummy  NArticles lnothers Article2or3_dummy Article5_dummy Article6_dummy Article8_dummy  Article10_dummy  Article13_dummy  P1_1dummy,  tvc( newdem3 execap INDIVIDUAL NArticles lnothers Article5_dummy Article6_dummy Article10_dummy ) texp(ln(_t)) 
  
mat def b=e(b)
mat def V=e(V)

mat list b
mat list V

/*identify position of variance of beta for constitutive and interaction terms*/
/*generate combined coef*/

gen combcoef = b[1,1] + ln(_t)*b[1,20]

gen se_combcoef = sqrt(V[1,1] + (ln(_t))^2*V[20,20] + 2*ln(_t)*V[1,20])


gen combcoef_lo = combcoef - 1.96*se_combcoef
gen combcoef_hi = combcoef + 1.96*se_combcoef


/******************************************/
/*** Relative Hazard for Binary Variable***/
/******************************************/
/*Following procedure to calculate combined coefficient, exponentiate to create the relative hazard*/
/*calculate relative hazard*/
gen relhaz = exp(combcoef)
/*calculate 95% confidence intervals*/
gen relhaz_lo = exp(combcoef_lo)
gen relhaz_hi = exp(combcoef_hi)
/*chart effect with confidence bounds*/

  *With overlaid histogram
  twoway (line relhaz relhaz_lo relhaz_hi _t if _t>365, sort clpattern(solid dash dash) clwidth(thick medium medium) ) ///
  (histogram _t, yaxis(2) fcolor(none) lcolor(ltbluishgray8) lwidth(thin) ) ///
 , ytitle(Relative Hazard New Versus Stable Democracy) yline(1) xtitle(Time Since Judgment) ///
   xlabel(0 1000 2000 3000 4000 5000) legend(off) scheme(s1mono)

   
   
  

use "C:\Users\ev42\Dropbox\ECHRCompliance\Replication\GrewalVoetendata.dta", clear
stset Duration , failure(Pending==0) 
stcox  newdem2 execap SepOp Importance grandchamber INDIVIDUAL JP_dummy LEG_dummy PRACT_dummy EXE_ADM_dummy  NArticles lnothers Article2or3_dummy Article5_dummy Article6_dummy Article8_dummy  Article10_dummy  Article13_dummy  P1_1dummy,  tvc( newdem2 execap INDIVIDUAL NArticles lnothers Article5_dummy Article6_dummy Article10_dummy ) texp(ln(_t)) 

set more off

**The following code builds on Amanda A. Licht, 2011, "Replication data for: Change Comes with Time", http://hdl.handle.net/1902.1/15633 IQSS Dataverse Network [Distributor] V3 [Version]

****************************/
*** Combined Coefficient ***/
****************************/
*Following estimation of the NPH model, generate combined coefficient and standard errors using parameters from the matrices stored in e(b) and e(V)*/

mat def b=e(b)
mat def V=e(V)

mat list b
mat list V

/*identify position of variance of beta for constitutive and interaction terms*/
/*generate combined coef*/

gen combcoef = b[1,1] + ln(_t)*b[1,20]
gen se_combcoef = sqrt(V[1,1] + (ln(_t))^2*V[20,20] + 2*ln(_t)*V[1,20])

gen combcoef_lo = combcoef - 1.96*se_combcoef
gen combcoef_hi = combcoef + 1.96*se_combcoef

gen combcoef2 = b[1,2] + ln(_t)*b[1,21]
gen se_combcoef2 = sqrt(V[2,2] + (ln(_t))^2*V[21,21] + 2*ln(_t)*V[2,21])


gen combcoef_lo2 = combcoef2 - 1.96*se_combcoef2
gen combcoef_hi2 = combcoef2 + 1.96*se_combcoef2

drop if _t>5000


twoway line combcoef2 combcoef_lo2 combcoef_hi2 _t if _t>365, sort clpattern(solid dash dash) clwidth(thick medium medium) ytitle(Coefficient) yline(0) xtitle(Days Since Judgment) ///
   xlabel(0 1000 2000 3000 4000 5000) xmtick(0(365)5000) title(A. Bureaucratic and Legal Capacity) legend(off) scheme(s1mono) 

*Figure 4b

set more off


use "C:\Users\ev42\Dropbox\ECHRCompliance\Replication\GrewalVoetendata.dta", clear

stset Duration, failure(Pending==0) 


stcox  POLCONIII execap SepOp Importance grandchamber INDIVIDUAL JP_dummy LEG_dummy PRACT_dummy EXE_ADM_dummy  NArticles lnothers Article2or3_dummy Article5_dummy Article6_dummy Article8_dummy  Article10_dummy  Article13_dummy  P1_1dummy, strata(ccode) tvc( POLCONIII execap INDIVIDUAL NArticles lnothers Article5_dummy Article6_dummy Article10_dummy ) texp(ln(_t)) 

outreg2 using tableone.doc, nolabel append


**The following code builds on Amanda A. Licht, 2011, "Replication data for: Change Comes with Time", http://hdl.handle.net/1902.1/15633 IQSS Dataverse Network [Distributor] V3 [Version]

****************************/
*** Combined Coefficient ***/
****************************/
*Following estimation of the NPH model, generate combined coefficient and standard errors using parameters from the matrices stored in e(b) and e(V)*/

mat def b=e(b)
mat def V=e(V)

mat list b
mat list V

/*identify position of variance of beta for constitutive and interaction terms*/
/*generate combined coef*/

gen combcoef = b[1,1] + ln(_t)*b[1,20]
gen se_combcoef = sqrt(V[1,1] + (ln(_t))^2*V[20,20] + 2*ln(_t)*V[1,20])

gen combcoef_lo = combcoef - 1.96*se_combcoef
gen combcoef_hi = combcoef + 1.96*se_combcoef

gen combcoef2 = b[1,2] + ln(_t)*b[1,21]
gen se_combcoef2 = sqrt(V[2,2] + (ln(_t))^2*V[21,21] + 2*ln(_t)*V[2,21])


gen combcoef_lo2 = combcoef2 - 1.96*se_combcoef2
gen combcoef_hi2 = combcoef2 + 1.96*se_combcoef2

drop if _t>5000


twoway line combcoef combcoef_lo combcoef_hi _t if _t>365, sort clpattern(solid dash dash) clwidth(thick medium medium) ytitle(Coefficient) yline(0) xtitle(Days Since Judgment) ///
   xlabel(0 1000 2000 3000 4000 5000) xmtick(0(365)5000) title(B. Checks and Balances) legend(off) scheme(s1mono) saving(pol, replace)  
  
  ***Table 1


use "C:\Users\ev42\Dropbox\ECHRCompliance\Replication\GrewalVoetendata.dta", clear

 set more off
stset Duration, failure(Pending==0) 

stcox  newdem2 execap SepOp Importance grandchamber INDIVIDUAL JP_dummy LEG_dummy PRACT_dummy EXE_ADM_dummy  NArticles lnothers Article2or3_dummy Article5_dummy Article6_dummy Article8_dummy  Article10_dummy  Article13_dummy  P1_1dummy, tvc( newdem2 execap INDIVIDUAL NArticles lnothers Article5_dummy Article6_dummy Article10_dummy ) texp(ln(_t)) 

outreg2 using tableone.doc, eform auto(2) nolabel replace

stcox  newdem3 execap No_Gen SepOp Importance grandchamber INDIVIDUAL JP_dummy LEG_dummy PRACT_dummy EXE_ADM_dummy  NArticles lnothers Article2or3_dummy Article5_dummy Article6_dummy Article8_dummy  Article10_dummy  Article13_dummy  P1_1dummy,  tvc( newdem3 execap INDIVIDUAL NArticles lnothers Article5_dummy Article6_dummy Article10_dummy ) texp(ln(_t)) 

outreg2 using tableone.doc, eform auto(2) nolabel append

use "C:\Users\ev42\Dropbox\ECHRCompliance\Replication\matcheddata2.dta", clear
stset Duration [iw=weights], failure(Pending==0) 
stcox  newdem2 execap SepOp Importance grandchamber INDIVIDUAL JP_dummy LEG_dummy PRACT_dummy EXE_ADM_dummy  NArticles lnothers Article2or3_dummy Article5_dummy Article6_dummy Article8_dummy  Article10_dummy  Article13_dummy  P1_1dummy,  tvc( newdem2 execap INDIVIDUAL NArticles lnothers Article5_dummy Article6_dummy Article10_dummy ) texp(ln(_t)) 

outreg2 using tableone.doc, eform auto(2) nolabel append


use "C:\Users\ev42\Dropbox\ECHRCompliance\Replication\matcheddata3.dta", clear
stset Duration [iw=weights], failure(Pending==0) 

stcox  newdem3 execap SepOp Importance grandchamber INDIVIDUAL JP_dummy LEG_dummy PRACT_dummy EXE_ADM_dummy  NArticles lnothers Article2or3_dummy Article5_dummy Article6_dummy Article8_dummy  Article10_dummy  Article13_dummy  P1_1dummy,  tvc( newdem3 execap INDIVIDUAL NArticles lnothers Article5_dummy Article6_dummy Article10_dummy ) texp(ln(_t)) 

outreg2 using tableone.doc, eform auto(2) nolabel append



use "C:\Users\ev42\Dropbox\ECHRCompliance\Replication\matcheddatahull2.dta", clear
stset Duration [iw=weights], failure(Pending==0) 
stcox  newdem2 execap SepOp Importance grandchamber INDIVIDUAL JP_dummy LEG_dummy PRACT_dummy EXE_ADM_dummy  NArticles lnothers Article2or3_dummy Article5_dummy Article6_dummy Article8_dummy  Article10_dummy  Article13_dummy  P1_1dummy,  tvc( newdem2 execap INDIVIDUAL NArticles lnothers Article5_dummy Article6_dummy Article10_dummy ) texp(ln(_t))  
outreg2 using tableone.doc, eform auto(2) nolabel append
stcox  newdem2 execap,  tvc( newdem2 execap) texp(ln(_t)) 
outreg2 using tableone.doc, eform auto(2) nolabel append


use "C:\Users\ev42\Dropbox\ECHRCompliance\Replication\matcheddatahull3.dta", clear
stset Duration [iw=weights], failure(Pending==0) 


stcox  newdem3 execap SepOp Importance grandchamber INDIVIDUAL JP_dummy LEG_dummy PRACT_dummy EXE_ADM_dummy  NArticles lnothers Article2or3_dummy Article5_dummy Article6_dummy Article8_dummy  Article10_dummy  Article13_dummy  P1_1dummy,  tvc( newdem3 execap INDIVIDUAL NArticles lnothers Article5_dummy Article6_dummy Article10_dummy ) texp(ln(_t))  
outreg2 using tableone.doc, eform auto(2) nolabel append
stcox  newdem3 execap,  tvc( newdem3 execap) texp(ln(_t))  
outreg2 using tableone.doc, eform auto(2) nolabel append

